//
//  LTSDKHelper.m
//  LTIM
//
//  Created by 俊松何 on 2017/3/31.
//  Copyright © 2017年 俊松何. All rights reserved.
//

#import "LTSDKHelper.h"
static LTSDKHelper *helper = nil;
@implementation LTSDKHelper

+(instancetype)shareHelper
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        helper = [[LTSDKHelper alloc] init];
    });
    return helper;
}

+(LTUser *)usertransformMTUser:(MTUserModel *)mtuser
{
     LTUser *user = [[LTUser alloc] init];
    user.type = LTUserTypeUser;
    user.userId = mtuser.userId;
    user.avatar = mtuser.avatar;
    user.name = mtuser.name;
    user.account = mtuser.account;
    user.cover = mtuser.info.cover;
    user.xToken = mtuser.token;
    user.signature = mtuser.info.signature;
    user.follow = mtuser.follow;
    return user;
}

+(LTUser *)usertransformWithGroup:(LTGroup *)groupModel
{
    LTUser *user = [[LTUser alloc] init];
    user.type = LTUserTypeGroup;
    user.avatar = groupModel.avatar;
    user.userId = groupModel.id;
    user.name = groupModel.name;
    
    return user;
}


+(LTUser *)usertransformWithuser:(LTUser *)user
{
    user.type = LTUserTypeUser;
    user.signature = @"";
    return user;
}


+(LTMessage *)sendMessagetoUserId:(NSString *)touserId
                           toUser:(LTUser *)toUser
                      messageType:(LTMessageType)messageType
                         chatType:(LTChatType)chattype
                       messageExt:(NSDictionary *)messageExt
{
    
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:messageType
                                                              body:nil
                                                          chatType:chattype
                                                               ext:nil];
    return message;
}

+ (LTMessage *)sendTextMessage:(NSString *)text
                      toUserId:(NSString *)touserId
                        toUser:(LTUser *)toUser
                   messageType:(LTMessageType)messageType
                      chatType:(LTChatType)chattype
                    messageExt:(NSDictionary *)messageExt
{
    
    LTMessageTextBody *body = [[LTMessageTextBody alloc] initWithText:text];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:messageType
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
      message.cellType = LTMessageCellSendText;
    
    return message;
}


/**
 发送打招呼消息
 
 @param text 文本
 @param touserId userId
 @param toUser 接收方User
 @return 返回message
 */
+ (LTMessage *)sendSayHelloMessage:(NSString *)text
                          toUserId:(NSString *)touserId
                            toUser:(LTUser *)toUser
{
    LTMessageTextBody *body = [[LTMessageTextBody alloc] initWithText:text];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeSayhello
                                                              body:body
                                                          chatType:LTChatTypeChat
                                                               ext:nil];
    message.cellType = LTMessageCellSendSayHello;
    return message;
}




+ (LTMessage *)sendAtTextMessage:(NSString *)text
                      toUserId:(NSString *)touserId
                        toUser:(LTUser *)toUser
                     atUserIds:(NSArray *)userIds
                   messageType:(LTMessageType)messageType
                      chatType:(LTChatType)chattype
{
    
    LTMessageAtTextBody *body = [[LTMessageAtTextBody alloc] initWithText:text userIds:userIds];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:messageType
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    message.cellType = LTMessageCellSendAtText;

    return message;

}




+ (LTMessage *)sendImageMessage:(UIImage *)image
                       toUserId:(NSString *)touserId
                         toUser:(LTUser *)toUser
                   messageType:(LTMessageType)messageType
                    chatType:(LTChatType)chattype
                    displayname:(NSString *)displayname
                    messageExt:(NSDictionary *)messageExt
{
    
    LTMessageImageBody *body = [[LTMessageImageBody alloc] initWithImage:image displayName:displayname];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:messageType
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    message.cellType = LTMessageCellSendImage;
    
    return message;
}


+ (LTMessage *)sendVoiceMessage:(NSData *)voiceData
                       toUserId:(NSString *)touserId
                         toUser:(LTUser *)toUser
                    messageType:(LTMessageType)messageType
                       chatType:(LTChatType)chattype
                    duration:(NSInteger )duration
                     messageExt:(NSDictionary *)messageExt
{
    

    LTMessageVoiceBody *body = [[LTMessageVoiceBody alloc] initWithData:voiceData duration:duration];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:messageType
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    message.cellType = LTMessageCellSendVoice;
    
    return message;
}

+ (LTMessage *)sendVideoMessage:(NSData *)videoData
                     coverimage:(UIImage *)coverimage
                       toUserId:(NSString *)touserId
                         toUser:(LTUser *)toUser
                    messageType:(LTMessageType)messageType
                       chatType:(LTChatType)chattype
                       duration:(NSInteger )duration
                     messageExt:(NSDictionary *)messageExt
{
    LTMessageVideoBody *body = [[LTMessageVideoBody alloc] initWithVideoData:videoData coverImage:coverimage duration:duration];
                                LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:messageType
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    message.cellType = LTMessageCellSendVideo;
    return message;
}

//位置消息
+ (LTMessage *)sendLocationMessage:(NSString *)address
                      latitude:(double)latitude
                     longitude:(double)longitude
                      toUserId:(NSString *)touserId
                        toUser:(LTUser *)toUser
                      chatType:(LTChatType)chattype
                    messageExt:(NSDictionary *)messageExt
{
    LTMessageLocationBody *body = [[LTMessageLocationBody alloc] initWithLatitude:latitude longitude:longitude address:address];
    
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeLocation
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    message.cellType = LTMessageCellSendLocation;
    return message;
}

+ (LTMessage *)sendBigBqMessageWithname:(NSString *)name
                            txt_msgType:(NSString *)txt_msgType
                               msg_data:(NSArray *)msg_data
                               toUserId:(NSString *)touserId
                                 toUser:(LTUser *)toUser
                               chatType:(LTChatType)chattype
{
    
    
    LTMessageBigBqBody *body = [[LTMessageBigBqBody alloc] initWithname:[NSString stringWithFormat:@"[%@]",name] txtMsgType:txt_msgType msgData:[msg_data mj_JSONString]];
    
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeBigBq
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    message.cellType = LTMessageCellSendBigBq;
    return message;





}


+ (LTMessage *)sendRedEnvelopeMessage:(NSString *)blessWorld
                                redID:(NSString *)redID
                             toUserId:(NSString *)touserId
                               toUser:(LTUser *)toUser
                             chatType:(LTChatType)chattype
                           messageExt:(NSDictionary *)messageExt
{
    LTMessageRedEnvelopeBody *body = [[LTMessageRedEnvelopeBody alloc] initWithRedEnvelopeID:redID blessWorld:blessWorld];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeRedBao
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    message.cellType = LTMessageCellSendRedBao;
    return message;

}

//发红包(luckmoney)
+(LTMessage *)sendLunkMoneyMessage:(NSString *)blessWorld
                           orderId:(NSString *)orderId
                          toUserId:(NSString *)touserId
                            toUser:(LTUser *)toUser
                          chatType:(LTChatType)chattype
                        messageExt:(NSDictionary *)messageExt
{
    LTMessageLuckMoneyBody *body = [[LTMessageLuckMoneyBody alloc] initWithLuckMoneyorderId:orderId blessWorld:blessWorld];
    
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeLuckMoney
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    message.cellType = LTMessageCellSendLuckMoney;
    return message;





}


//发送名片
+ (LTMessage *)sendPresonCardMessage:(LTUser *)cardUser
                            toUserId:(NSString *)touserId
                              toUser:(LTUser *)toUser
                            chatType:(LTChatType)chattype
                          messageExt:(NSDictionary *)messageExt
{
    LTMessagePersonCardBody *body = [[LTMessagePersonCardBody alloc] init];
    body.userId = cardUser.userId;
    body.avatar = cardUser.avatar;
    body.name   = cardUser.name;
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:touserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:touserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypePersonCard
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    message.cellType = LTMessageCellSendPersonCard;
    return message;




}

+(LTMessage *)sendLuckMoneyGetMessage:(NSString *)operationname
                      operationresult:(NSString *)operationresult
                             toUserId:(NSString *)groupId
                               toUser:(LTUser *)toUser
                             chatType:(LTChatType)chatType
                           messageExt:(NSDictionary *)messageExt
{

    LTMessageGroupOperationBody *body = [[LTMessageGroupOperationBody alloc] initWithoperationname:operationname operationresult:operationresult];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:groupId
                                                        fromUserId:fromUser.userId
                                                          toUserId:groupId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeRECEIVERedBao
                                                              body:body
                                                          chatType:chatType
                                                               ext:nil];
    
    return message;
}

//转账消息
+(LTMessage *)sendETHTransferId:(NSString *)transferId
                         remark:(NSString *)remark
                  transferMoney:(NSString *)transferMoney
                           unit:(NSString *)unit
                         toUser:(LTUser *)toUser
{
    LTMessageETHTransferBody *body = [[LTMessageETHTransferBody alloc] initWithtransferId:transferId remark:remark transferMoney:transferMoney unit:unit];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:toUser.userId
                                                        fromUserId:fromUser.userId
                                                          toUserId:toUser.userId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeETHTransfer
                                                              body:body
                                                          chatType:LTChatTypeChat
                                                               ext:nil];
        message.cellType = LTMessageCellSendETHTransfer;
    return message;
}

//发送群操作消息
+ (LTMessage *)sendGroupOperationMessage:(NSString *)operationname
                         operationresult:(NSString *)operationresult
                                toUserId:(NSString *)groupId
                                  toUser:(LTUser *)toUser
                            messageType:(LTMessageType)messageType
                              messageExt:(NSDictionary *)messageExt
{
    LTMessageGroupOperationBody *body = [[LTMessageGroupOperationBody alloc] initWithoperationname:operationname operationresult:operationresult];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:groupId
                                                        fromUserId:fromUser.userId
                                                          toUserId:groupId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:messageType
                                                              body:body
                                                          chatType:LTChatTypeGroupChat
                                                               ext:nil];
    
    return message;
}

//发送消息撤回消息
+( LTMessage *)sendRevokeMessageWithMessageID:(NSString *)revokeMessageId
                                     toUserId:(NSString *)toUserId
                                       toUser:(LTUser *)toUser
                                    chatType:(LTChatType)chattype
{
    LTMessageCmdBody *body = [[LTMessageCmdBody alloc] initWithType:LTMessageCmdTypeMessageRevoke data:revokeMessageId];
   LTUser *fromUser = [LTClient sharedClient].currentUser;
    
    LTMessage *message = [[LTMessage alloc] initWithConversationID:toUserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:toUserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeCMD
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    return message;
}
//本地插入消息撤回的UI展示消息
+ (LTMessage *)makeRevkeUIMessageWithtoUserId:(NSString *)toUserId
                               toUser:(LTUser *)toUser
                             chatType:(LTChatType)chattype
{
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessageGroupOperationBody *body = [[LTMessageGroupOperationBody alloc] initWithoperationname:fromUser.name operationresult:@"撤回了一条消息"];
    
    
    LTMessage *message = [[LTMessage alloc] initWithConversationID:toUserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:toUserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeMessageRevoke
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    return message;
}
//发送消息是发现没有权限提示自己没有权限的消息
+ (LTMessage *)makeNOPermissionUIMessageWithUserId:(NSString *)toUserId
                                            toUser:(LTUser *)toUser
                                          chatType:(LTChatType)chattype
{
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessageGroupOperationBody *body = [[LTMessageGroupOperationBody alloc] initWithoperationname:fromUser.name operationresult:@"消息已发出，但被对方拒收了"];
    
    
    LTMessage *message = [[LTMessage alloc] initWithConversationID:toUserId
                                                        fromUserId:fromUser.userId
                                                          toUserId:toUserId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeNOPermission
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    return message;

    

}




+(LTMessage *)sendKickedOutgroupMessageWithUser:(LTUser *)kickedUser groupId:(NSString *)groupId
{
    LTMessageCmdBody *body = [[LTMessageCmdBody alloc] initWithType:LTMessageCmdTypeKickedOutGroup data:groupId];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    
    LTMessage *message = [[LTMessage alloc] initWithConversationID:kickedUser.userId
                                                        fromUserId:fromUser.userId
                                                          toUserId:kickedUser.userId
                                                          fromUser:fromUser
                                                            toUser:kickedUser
                                                              type:LTMessageTypeCMD
                                                              body:body
                                                          chatType:LTChatTypeChat
                                                               ext:nil];
    return message;
}


+(LTMessage *)sendCallTipMessage:(LTUser *)toUser
                            type:(CallType)type
                          status:(CallStatus)status
                    callDuration:(NSString *)callDuration
{

    LTMessageCallTipBody *body = [[LTMessageCallTipBody alloc] initWithtype:type status:status callDuration:callDuration];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    
    LTMessage *message = [[LTMessage alloc] initWithConversationID:toUser.userId
                                                        fromUserId:fromUser.userId
                                                          toUserId:toUser.userId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeCallTip
                                                              body:body
                                                          chatType:LTChatTypeChat
                                                               ext:nil];
    message.cellType = LTMessageCellSendCallTip;
    return message;

}

//截屏通知消息
+(LTMessage *)sendScreenshotName:(NSString *)name
                          result:(NSString *)result
                          toUser:(LTUser *)toUser
                        chatType:(LTChatType)chattype
{
    
    LTMessageGroupOperationBody *body = [[LTMessageGroupOperationBody alloc] initWithoperationname:name operationresult:result];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:toUser.userId
                                                        fromUserId:fromUser.userId
                                                          toUserId:toUser.userId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeScreenShots
                                                              body:body
                                                          chatType:chattype
                                                               ext:nil];
    
    return message;
  
}

//直播间里面普通聊天消息
+(LTMessage *)sendChatRoomNoramlMessage:(NSString *)content roomId:(NSString *)roomId
{
    LTMessageTextBody *body = [[LTMessageTextBody alloc] initWithText:content];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTUser *toUser = [[LTUser alloc] init];
    toUser.userId = roomId;
    toUser.type =  LTUserTypeCHATROOM;
    toUser.name = roomId;
    
    LTMessage *message = [[LTMessage alloc] initWithConversationID:roomId
                                                        fromUserId:fromUser.userId
                                                          toUserId:roomId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeText
                                                              body:body
                                                          chatType:LTChatTypeChatRoom
                                                               ext:nil];
    return message;
}

//点亮消息
+(LTMessage *)sendLightUpMessageRoomId:(NSString *)roomId isFrist:(BOOL)frist
{
    LTMessageLightUpBody *body = [[LTMessageLightUpBody alloc] init];
    body.isFirst = frist;
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTUser *toUser = [[LTUser alloc] init];
    toUser.userId = roomId;
    toUser.type =  LTUserTypeCHATROOM;
    toUser.name = roomId;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:roomId
                                                        fromUserId:fromUser.userId
                                                          toUserId:roomId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeLightUp
                                                              body:body
                                                          chatType:LTChatTypeChatRoom
                                                               ext:nil];
    return message;
}


//直播间里面弹幕消息
+(LTMessage *)sendChatRoomBarrageMessage:(NSString *)content roomId:(NSString *)roomId
{
    LTMessageTextBody *body = [[LTMessageTextBody alloc] initWithText:content];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTUser *toUser = [[LTUser alloc] init];
    toUser.userId = roomId;
    toUser.type =  LTUserTypeCHATROOM;
    toUser.name = roomId;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:roomId
                                                        fromUserId:fromUser.userId
                                                          toUserId:roomId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeBarrage
                                                              body:body
                                                          chatType:LTChatTypeChatRoom
                                                               ext:nil];
    return message;
}

//主播关闭直播消息
+(LTMessage *)sendCloseLiveMessageRoomId:(NSString *)roomId
{
    LTMessageBody *body = [[LTMessageBody alloc] init];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTUser *toUser = [[LTUser alloc] init];
    toUser.userId = roomId;
    toUser.type =  LTUserTypeCHATROOM;
    toUser.name = roomId;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:roomId
                                                        fromUserId:fromUser.userId
                                                          toUserId:roomId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeCloseLive
                                                              body:body
                                                          chatType:LTChatTypeChatRoom
                                                               ext:nil];
    return message;
}

//直播间的礼物消息
+(LTMessage *)sendGiftMessageWithGiftModel:(giftModel *)giftmodel roomId:(NSString *)roomId
{
    LTMessageGiftBody *body = [[LTMessageGiftBody alloc] init];
    body.giftId = giftmodel.id;
    body.giftName = giftmodel.title;
    body.giftImage = giftmodel.image;
    body.number = giftmodel.number;
    body.animation = giftmodel.animation;
    body.englishTitle = giftmodel.englishTitle;
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTUser *toUser = [[LTUser alloc] init];
    toUser.userId = roomId;
    toUser.type =  LTUserTypeCHATROOM;
    toUser.name = roomId;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:roomId
                                                        fromUserId:fromUser.userId
                                                          toUserId:roomId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeGift
                                                              body:body
                                                          chatType:LTChatTypeChatRoom
                                                               ext:nil];
    return message;
}


//LTMessageTypeRoomNormal        = 4003,  //直播间普通文本消息
//LTMessageTypeRoomJoin          = 4004,  //进入直播间消息
//LTMessageTypeRoomSetManager    = 4005,  //设置为管理员
//LTMessageTypeRoomCancelManager = 4006,  //取消管理员
//LTMessageTypeRoomMute          = 4007,  //禁言用户
//LTMessageTypeRoomCancelMute    = 4008,  //取消禁言
//LTMessageTypeRoomKickout       = 4009,  //踢出用户
//LTMessageTypeRoomUpdateTitle   = 4010,  //更新title




//进入房间消息
+(LTMessage *)sendJoinRoomMessageRoomId:(NSString *)roomId
{
    LTMessageBody *body = [[LTMessageBody alloc] init];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTUser *toUser = [[LTUser alloc] init];
    toUser.userId = roomId;
    toUser.type =  LTUserTypeCHATROOM;
    toUser.name = roomId;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:roomId
                                                        fromUserId:fromUser.userId
                                                          toUserId:roomId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeRoomJoin
                                                              body:body
                                                          chatType:LTChatTypeChatRoom
                                                               ext:nil];
    return message;
}


//进入房间消息
+(LTMessage *)sendRoomMessageRoomId:(NSString *)roomId
                      operationUser:(LTUser *)operationUser
                        messagetype:(LTMessageType)type
{
    LTMessageRoomOperationBody *body = [[LTMessageRoomOperationBody alloc] init];
    body.operationUser = operationUser;
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTUser *toUser = [[LTUser alloc] init];
    toUser.userId = roomId;
    toUser.type =  LTUserTypeCHATROOM;
    toUser.name = roomId;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:roomId
                                                        fromUserId:fromUser.userId
                                                          toUserId:roomId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:type
                                                              body:body
                                                          chatType:LTChatTypeChatRoom
                                                               ext:nil];
    return message;
}

//更新直播间title消息
+(LTMessage *)updateRoomTitleMessageRoomId:(NSString *)roomId
                                     title:(NSString *)title
{
    
    LTMessageUpdateTitleBody *body = [[LTMessageUpdateTitleBody alloc] init];
    body.title = title;
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTUser *toUser = [[LTUser alloc] init];
    toUser.userId = roomId;
    toUser.type =  LTUserTypeCHATROOM;
    toUser.name = roomId;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:roomId
                                                        fromUserId:fromUser.userId
                                                          toUserId:roomId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeRoomUpdateTitle
                                                              body:body
                                                          chatType:LTChatTypeChatRoom
                                                               ext:nil];
    return message;
    
}

+(LTMessage *)focusHostMessageRoomId:(NSString *)roomId
{
    LTMessageBody *body = [[LTMessageBody alloc] init];
    LTUser *fromUser = [LTClient sharedClient].currentUser;
    LTUser *toUser = [[LTUser alloc] init];
    toUser.userId = roomId;
    toUser.type =  LTUserTypeCHATROOM;
    toUser.name = roomId;
    LTMessage *message = [[LTMessage alloc] initWithConversationID:roomId
                                                        fromUserId:fromUser.userId
                                                          toUserId:roomId
                                                          fromUser:fromUser
                                                            toUser:toUser
                                                              type:LTMessageTypeRoomFocusHost
                                                              body:body
                                                          chatType:LTChatTypeChatRoom
                                                               ext:nil];
    return message;
}





+(NSString *)MessageFromatString:(LTMessage *)message
{

    NSString *fromatStr = [NSString string];
    
    if(message.extra != nil && message.messageType != LTMessageTypeMessageRevoke){
        fromatStr = @"[悄悄话]";
        return  fromatStr;
    }
    switch (message.messageType) {
            
        case LTMessageTypeText:{  LTMessageTextBody *body =(LTMessageTextBody *)message.body;
            fromatStr  = body.text;    break;
        }
        case LTMessageTypeSayhello:{
            if (message.cellType == LTMessageCellRecvSayHello)
            {
                fromatStr = @"同意了你的加好友申请，现在开始聊天吧";
            }else
            {
                fromatStr = [NSString stringWithFormat:@"你已经添加了%@，现在可以聊天了",message.target.name];
            }
            
        }break;
            
        case LTMessageTypeAtText:{  LTMessageAtTextBody *body =(LTMessageAtTextBody *)message.body;
            fromatStr  = body.text;    break;
        }
            
            
        case LTMessageTypeImage:    fromatStr    = NSLTLocalizedString(@"message.image1", @"Image");   break;
        case LTMessageTypeVoice:    fromatStr    =  NSLTLocalizedString(@"message.voice1", @"Voice");   break;
        case LTMessageTypeLocation: fromatStr    = NSLTLocalizedString(@"message.location1", @"Location");   break;
        case LTMessageTypeRedBao:   fromatStr   =  NSLTLocalizedString(@"message.redbao", @"message.redbao");break;
        case LTMessageTypeVideo:    fromatStr    = NSLTLocalizedString(@"message.video1", @"Video");   break;
        case LTMessageTypeFile:     fromatStr =   NSLTLocalizedString(@"message.file", nil);   break;
        case LTMessageTypeBigBq:    {
                                    LTMessageBigBqBody *body = (LTMessageBigBqBody *)message.body;
                                    fromatStr = body.text;
        }break;
        case LTMessageTypeCallTip:{
            LTMessageCallTipBody *body = (LTMessageCallTipBody *)message.body;
            if(body.type == CallTypeVoice)
            {
                 fromatStr = NSLTLocalizedString(@"message.voiceCall", nil);
            }else
            {
                fromatStr = NSLTLocalizedString(@"message.videoCall", nil);
            }
        
        }break;
            
        case LTMessageTypeRECEIVERedBao:{
            LTMessageGroupOperationBody *body = (LTMessageGroupOperationBody *)message.body;
            
            if([body.operationName isEqualToString:[LTClient sharedClient].currentUser.name])
            {
                if([body.operationResult isEqualToString:[LTClient sharedClient].currentUser.name])
                {
                    
                    fromatStr = NSLTLocalizedString(@"message.redTip1", nil);
                    
                }else
                {
                    
                    fromatStr = [NSString stringWithFormat:NSLTLocalizedString(@"message.redTip2", nil),body.operationResult];
                }
                
            }else
            {
                if([body.operationResult isEqualToString:[LTClient sharedClient].currentUser.name])
                {
                    fromatStr = [NSString stringWithFormat:NSLTLocalizedString(@"message.redTip3", nil),body.operationName];
                }else
                {
                    fromatStr = [NSString stringWithFormat:NSLTLocalizedString(@"message.redTip4", nil),body.operationName,body.operationResult];
                }
            }
            
            
        }break;
            
            
        case LTMessageTypeCreateGroup:{
            LTMessageGroupOperationBody *body = (LTMessageGroupOperationBody *)message.body;
            fromatStr = [NSString stringWithFormat:NSLTLocalizedString(@"message.groupTip1",nil),body.operationName,body.operationResult];
            
            
            
        }break;
        case LTMessageTypeaddGroupMember:{
            
            LTMessageGroupOperationBody *body = (LTMessageGroupOperationBody *)message.body;
            fromatStr = [NSString stringWithFormat:NSLTLocalizedString(@"message.groupTip2",nil),body.operationName,body.operationResult];
            
        }break;
            
            
        case LTMessageTypeaddGroupQRMember:{
            
            LTMessageGroupOperationBody *body = (LTMessageGroupOperationBody *)message.body;
            fromatStr = [NSString stringWithFormat:NSLTLocalizedString(@"message.groupTip3", nil),body.operationName,body.operationResult];
            
        }break;
            
        case LTMessageTypedeleteGroupMember:{
            
            LTMessageGroupOperationBody *body = (LTMessageGroupOperationBody *)message.body;
            fromatStr = [NSString stringWithFormat:NSLTLocalizedString(@"message.groupTip4",nil),body.operationName,body.operationResult];
            
        }break;
            
        case LTMessageTypechangeGroupName:{
            
            LTMessageGroupOperationBody *body = (LTMessageGroupOperationBody *)message.body;
            fromatStr = [NSString stringWithFormat:NSLTLocalizedString(@"message.groupTip5",nil),body.operationName,body.operationResult];
            
        }break;
            
        case LTMessageTypechangeGroupnotice:{
            
            LTMessageGroupOperationBody *body = (LTMessageGroupOperationBody *)message.body;
            fromatStr = [NSString stringWithFormat:NSLTLocalizedString(@"message.groupTip6",nil),body.operationName,body.operationResult];
        } break;
        case LTMessageTypeScreenShots:{
            LTMessageGroupOperationBody *body  = (LTMessageGroupOperationBody *)message.body;
            if(body.operationName != nil)
            {
                fromatStr = [NSString stringWithFormat:@"%@在聊天页面截取了屏幕",body.operationName];
            }
        }break;
        case LTMessageTypeMessageRevoke:
        {
             LTMessageGroupOperationBody *body = (LTMessageGroupOperationBody *)message.body;
            fromatStr = [NSString stringWithFormat:NSLTLocalizedString(@"message.reovkeTip1",nil),body.operationName];
        
        } break;
        case LTMessageTypeNOPermission:
        {
            fromatStr = NSLTLocalizedString(@"message.refuseTip",nil);
        }break;
        case LTMessageTypeGzh:
        {
            fromatStr = NSLTLocalizedString(@"message.gzhwz",nil);
        } break;
        case LTMessageTypeETHTransfer:
        {
            fromatStr = @"[转账]";
        }break;
        case LTMessageTypeShareGzh:
        {
            fromatStr = NSLTLocalizedString(@"message.gzhcard", nil);
        }break;
        case LTMessageTypeLink:
        {
            fromatStr = NSLTLocalizedString(@"message.link", nil);
        }break;
        case LTMessageTypePersonCard:
        {
            fromatStr = NSLTLocalizedString(@"message.personcard", nil);
        }break;
        case LTMessageTypeLuckMoney:
        {
            fromatStr = NSLTLocalizedString(@"message.redbao", nil);
        }break;
        default:
            break;
    }
    return  fromatStr;
}


@end
